package com.googlecode.tracey.audit;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static java.util.regex.Pattern.MULTILINE;

public class StringPayload {

    private final String text;

    public StringPayload(String text) {
        this.text = text;
    }

    public boolean contains(String text) {
        return this.text.contains(text);
    }

    public boolean matches(String regexp) {
        return Pattern.compile(regexp, MULTILINE).matcher(text).find();
    }

    public String extract(String regex) {
        Pattern p = Pattern.compile(".*"+regex, Pattern.MULTILINE);
        Matcher m = p.matcher(text);
        if (m.find()){
            return m.group(1);
        }
        return "UNKNOWN";
    }
}
